Skip to content

Read TARGET and a boolean renew in debug mode - #87

Merged
ioigoume merged 2 commits into
masterfrom
fix/debug-mode-target
Nov 16, 2026
Merged

ioigoume merged 2 commits into
masterfrom
fix/debug-mode-target

Conversation

@cicnavi

@cicnavi cicnavi commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

handleDebugMode() validated the ticket it had just issued against the service from a lowercase 'target' parameter, which no client sends: login() and the validation endpoints read 'TARGET'. With only TARGET given, debug mode therefore answered "Missing service parameter". It also passed the 'renew' query string straight to validate(), which takes a bool, so renew=true failed with a TypeError under strict types.

Read 'TARGET', convert 'renew' with FILTER_VALIDATE_BOOL, and test debug mode with service and with TARGET, each with and without renew.

Assisted-by: Claude Code (claude-opus-5-5, implementation & unit tests)
Assisted-by: Google Antigravity (gemini-3.8-flash-high, review)

handleDebugMode() validated the ticket it had just issued against the
service from a lowercase 'target' parameter, which no client sends:
login() and the validation endpoints read 'TARGET'. With only TARGET
given, debug mode therefore answered "Missing service parameter". It
also passed the 'renew' query string straight to validate(), which
takes a bool, so renew=true failed with a TypeError under strict types.

Read 'TARGET', convert 'renew' with FILTER_VALIDATE_BOOL, and test debug
mode with service and with TARGET, each with and without renew.

Assisted-by: Claude Code (claude-opus-5-5, implementation & unit tests)
Assisted-by: Google Antigravity (gemini-3.8-flash-high, review)
@cicnavi
cicnavi requested a review from ioigoume November 11, 2026 15:09
@codecov

codecov Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 71.51%. Comparing base (618b649) to head (6ba4d18).

Additional details and impacted files
@@             Coverage Diff              @@
##             master      #87      +/-   ##
============================================
+ Coverage     69.70%   71.51%   +1.81%     
  Complexity      394      394              
============================================
  Files            25       25              
  Lines          1274     1278       +4     
============================================
+ Hits            888      914      +26     
+ Misses          386      364      -22     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread src/Controller/LoginController.php Outdated
method: 'serviceValidate',
renew: $request->get('renew', false),
target: $request->get('target'),
// The query parameter is a string, validate() takes a bool

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cicnavi

Thanks for catching this! Could we go one step further and remove the $request->get(...) / $request->query->get(...) calls from handleDebugMode() entirely? login() could pass the values it has already parsed straight into it.

login() already gets bool $renew, ?string $TARGET and ?string $service through #[MapQueryParameter], so Symfony has already read and validated them. Right now handleDebugMode() reads them from the request a second time, which repeats the parsing. That's also why filter_var is needed. Reading them twice causes a few problems:

  • Different sources: Request::get() checks route attributes first, then the query string, then the POST body. login() only reads the query string. A POST body or route attribute with TARGET / renew could therefore reach the validation even though the ticket was never issued with it.
  • Different parsing: an invalid value such as renew=yes-please is rejected by login()'s mapper, but filter_var quietly turns it into false. Array input (TARGET[]=x) causes a TypeError.
  • Different result: in any of these cases, debug mode isn't validating the ticket under the conditions it was issued with (forceAuthn = $renew, service = $service ?? $TARGET). Checking exactly that is the whole point of debug mode.
  • Deprecation: Request::get() is deprecated in Symfony 7.4.

If login() passes its mapped values, there's only one source of truth. filter_var and its import can go, and every value is type-checked by Symfony up front. Adding the new parameters at the end with defaults keeps existing callers of this public method working:

// login(): also map pgtUrl
#[MapQueryParameter] ?string $pgtUrl = null,
// ...
[$templateName, $statusCode, $DebugModeXmlString] = $this->handleDebugMode(
    $request,
    $debugMode,
    $serviceTicket,
    $renew,
    $TARGET,
    $service,
    $pgtUrl,
);

// handleDebugMode()
public function handleDebugMode(
    Request $request,
    ?string $debugMode,
    array $serviceTicket,
    bool $renew = false,
    ?string $target = null,
    ?string $service = null,
    ?string $pgtUrl = null,
): array {
    // ...
    $xmlResponse = $this->validate(
        request: $request,
        method:  'serviceValidate',
        renew:   $renew,
        target:  $target,
        ticket:  $serviceTicket['id'],
        service: $service,
        pgtUrl:  $pgtUrl,
    );

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, good call. login() now also maps pgtUrl and passes renew, TARGET, service and pgtUrl to handleDebugMode() as trailing optional parameters, so filter_var and every Request::get() call are gone from it. I also added a test that renew, service or an array TARGET in the POST body no longer changes the result (all three cases failed on the previous code), and updated the ChangeLog entry.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, good call. login() now also maps pgtUrl and passes renew, TARGET, service and pgtUrl to handleDebugMode() as trailing optional parameters, so filter_var and every Request::get() call are gone from it. I also added a test that renew, service or an array TARGET in the POST body no longer changes the result (all three cases failed on the previous code), and updated the ChangeLog entry.

Thanks, Marko! The request-body tests are a nice addition! LGTM. :)

handleDebugMode() read renew, TARGET, service and pgtUrl with
Request::get(), a second time after login() had already mapped them
with #[MapQueryParameter]. Request::get() also falls back to route
attributes and the POST body, skips the mapper's validation, and is
deprecated in Symfony 7.4. A renew or service in the POST body
therefore changed what debug mode validated, and an array TARGET
failed with a TypeError.

login() now also maps pgtUrl and passes its own values to
handleDebugMode(), so the ticket is validated with the parameters it
was issued with. The new parameters are trailing and optional, so the
public signature stays compatible, and filter_var() is no longer
needed. As suggested in the PR 87 review.

Test that renew, service or an array TARGET in the POST body does not
change the result, and share the debug-mode tests' setup.

Assisted-by: Claude Code (claude-opus-5-5, implementation & unit tests)
@ioigoume
ioigoume merged commit 0b2678f into master Nov 16, 2026
38 checks passed
cicnavi added a commit that referenced this pull request Nov 16, 2026
Bring in the debug-mode fixes (#87, #88). The only conflict was in
docs/ChangeLog.md, where both sides added [Unreleased] entries; they
are now combined into one Changed and one Fixed section.

Assisted-by: Claude Code (claude-opus-5-5, conflict resolution)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants